
const fs = require('fs');
const chalk = require('chalk'); //命令行输出样式美化
const config = require('../config.js');
module.exports = async (projectName,cmd) => {
      upDateConfig(projectName)
 }

const upDateConfig = (projectName)=>{
  let flag = false
  config.buildCheckbox[0].choices.some(package=>{
      if(package == projectName){
          console.log(chalk.red(`The ${projectName} project template already exist`));
          flag = true
          return;
      }
  })
  if(!flag){
    config.serveList[0].choices.push(projectName)
    config.buildCheckbox[0].choices.push(projectName)
    
    fs.writeFile(__dirname + '/../config.js', "module.exports  ="+JSON.stringify(config,"","\t"), 'utf-8', (err) => {
        if (err) console.log(err)
        console.log(chalk.green('New template added!\n'))
        console.log(chalk.grey('The last template list is: \n'))
        console.log(config.buildCheckbox[0].choices)
        console.log('\n')
        console.log(chalk.green(`✔ The ${projectName} project template successfully add`));
    })
  }
  
  
}